Skip to content

Check unused cppia casts to classes and interfaces under the JIT - #501

Merged
dimensionscape merged 1 commit into
mainfrom
fix/cppia-jit-unused-casts
Nov 28, 2026
Merged

dimensionscape merged 1 commit into
mainfrom
fix/cppia-jit-unused-casts

Conversation

@dimensionscape

Copy link
Copy Markdown
Member

For 6.0.3.

Under the cppia JIT, a cast whose value goes unused, such as cast(o, SomeInterface); as a statement, checked nothing, so a failing cast ran on where the interpreter and compiled code throw:

var o:Dynamic = new NotAnI();
cast(o, I);            // interpreted and compiled: throws; jitted: nothing
trace("must not run");

It was so in jitted methods on main. It showed once the JIT compiled local functions on the branch of #500: Haxe's TestCasts.testInterfaces makes such casts in closures, as exc(function() cast(v, I2)), and failed three assertions there.

Cause and change

CastExpr::genCode in src/hx/cppia/Cppia.cpp compiled an unused cast as its value alone, whatever the kind of cast. Now only the unused casts that cannot fail are left out: to Dynamic, and the unchecked Int, Float, Bool and String conversions. A cast to a class or interface checks, and an array conversion runs, as the interpreter's do.

Tests

test/regression/CppiaJitUnusedCasts casts to an interface and to a class, passing and failing, as statements in closures and in methods, used, and before a statement that must not run. It runs them as compiled code and as a script, interpreted and jitted, and checks that all three agree. Without the fix the jitted run let every failing cast through.

The fix was found and tested on the #500 branch, where it is commit d74ecf2, and cherry-picked onto main here with only its Changes.md line.

The JIT compiled a cast whose value goes unused, such as cast(o, I) as
a statement, as its value alone, for every kind of cast. A cast to a
class or interface is a check that can fail, so one that failed ran on
under the JIT, where the interpreter and compiled code throw. It was so
in jitted methods before, and Haxe's unit suite met it once the JIT
compiled local functions: TestCasts.testInterfaces makes such casts in
closures, as exc(function() cast(v, I2)), and failed three assertions
under the JIT on this branch while passing on main.

Only the unused casts that cannot fail, to Dynamic and the unchecked
Int, Float, Bool and String conversions, are left out now. A cast to a
class or interface checks, and an array conversion runs, as the
interpreter's do.

CppiaJitUnusedCasts casts to an interface and to a class, passing and
failing, as statements in closures and in methods, used, and before a
statement that must not run, as compiled code and as a script
interpreted and jitted, and checks that all three agree. Without the fix
the jitted run let every failing cast through.

Tests: CppiaJitUnusedCasts
@dimensionscape
dimensionscape merged commit b6981ce into main Nov 28, 2026
37 checks passed
dimensionscape added a commit that referenced this pull request Nov 29, 2026
main adds the host_statics cppia workload, which joins the shared
workload table here, so the cppia and HashLink harnesses both run it.
This branch's Changes.md lines move under libhxcpp 6.1.0, and main has
the unused cppia cast fix (#501) under 6.0.3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant